package com.jackrain.nea.omslocal.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.jackrain.nea.core.db.SPResult;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.util.ValueHolder;
import com.jackrain.nea.web.query.QueryEngine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

/**
 * @Discription: 保存奇门传DRP 消息回执
 * Created with IntelliJ IDEA.
 * @Author cs
 * @Date 2018/3/15 15:05
 */
@Component
@Slf4j
public class SaveQiMenDrpDeliceryorderRetService {

    /**
     * 保存奇门传 DRP 消息 回执
     *
     * @param jsonArray
     */
    public void saveDrpDeliceryorderRet(JSONArray jsonArray, String msgkey, String topic) {


        if (!jsonArray.isEmpty()) {

            // 当前系统时间
            Date sysDate = new Date(System.currentTimeMillis());
            // 修改数据为已同步
            String updateSql = "update t_omserperporder set Read_status = 2,code = ?,msg = ?  where id = ?";

            for (Object obj : jsonArray) {
                // 获取id
                JSONObject tempJsonObj = JSONObject.parseObject(obj.toString(), Feature.OrderedField);
                String id = tempJsonObj.getString("order");

                // 回传成功,修改状态
                QueryEngine.getInstance().executeUpdate(updateSql, new Object[]{0, "success", id});

            }
        }
    }


}
